import 'dart:convert';

import 'package:favourcate/core/model/category_model.dart';
import 'package:flutter/services.dart';

class JsonParse {
  static Future<List<GLCategoryModel>> getCategoryData () async {
    // 1. 加载 json 文件
    final jsonString = await rootBundle.loadString('assets/json/category.json');
    // 2. 将 jsonString 转成 Map 或 List
    final result = json.decode(jsonString);
    // 3. 将Map中的内容转成一个一个的对象
    final resultList = result['category'];
    List<GLCategoryModel> categories = [];
    for (var json in resultList) {
      categories.add(GLCategoryModel.fromJson(json));
    }
    return categories;
  }
}